﻿using CxRomos.Core.Domain.Entities;
using FluentNHibernate.Mapping;

namespace CxRomos.Core.Domain.Mappings {
    public class PermissionMap : ClassMap<Permission> {
        public PermissionMap() {
            Table("[dbo].[Permissions]");
            OptimisticLock.Version();
            LazyLoad();

            Id(x => x.PermissionId)
                .Column("PermissionId")
                .GeneratedBy.Identity();

            Map(x => x.Name);

            HasMany(x => x.AccountPermissions)
                .Cascade.AllDeleteOrphan()
                .AsSet()
                .Inverse()
                .LazyLoad()
                .KeyColumns.Add("PermissionId");

        }
    }
}
